/**
 * 验证用户名不为空
 */
function checkUserName(){
	var userName = $.trim($("#username").val());
	var falg = true;
	if(userName == null || userName == "" || userName == "用户名"){
		layer.tips("请输入用户名", "#username", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}

/**
 * 验证密码不为空
 */
function checkPassWord(){
	var password = $.trim($("#password").val());
	var falg = true;
	if(password == null || password == "" || password == "密码"){
		layer.tips("请输入密码", "#password", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}

/**
 * 验证重复密码确认性不为空
 */
function checkrePassWord(){
	var password = $.trim($("#password").val());
	var repassword=$.trim($("#repassword").val());
	var falg = true;
	if(password!=repassword){
		layer.tips("请重新输入密码，密码两次不正确", "#repassword", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}

/**
 * 验证手机不为空，且正则验证
 */
function checkPhone(){
	var phone = $.trim($("#phone").val());
	var falg = true;
	if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))||phone == null || phone == "" || phone == "手机"){
		layer.tips("请输入手机号,或者手机号格式不对", "#phone", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}

/**
 * 验证手机不为空，且正则验证
 */
function checkEmail(){
	var email = $.trim($("#email").val());
	var emailmsg=/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
	var falg = true;
	if(!(emailmsg.test(email))||email == null || email == "" || email == "邮箱"){
		layer.tips("请输入邮箱", "#email", {tips: [2, "#E34127"],time: 500});
		falg = false;
	}
	return falg;
}

function register(){

		var userName = $.trim($("#username").val());
		var passWord = $.trim($("#repassword").val());
		var phone= $.trim($("#phone").val());
		var email= $.trim($("#email").val());	
		$.ajax({
			type : "post",
			url : "/member/register.action",
			async : false,
			data : {
				userName : userName,
				passWord : passWord,
				phone:phone,
				email:email
			},
			dataType:"json",
			success : function(data){
				if(data.code == 0){
					layer.msg(data.msg, {icon: 6}, function(){
						location.href =  "/member/page/login.html";
					});
	
				}else{
					layer.msg(data.msg, {icon: 5});
				}
			}
		});

}
//回车触发登录
function keyLogin(e){
	  var theEvent = window.event || e;
	      var code = theEvent.keyCode || theEvent.which;
	   if (code==13) {  //回车键的键值为13
		   register();  //调用提交登录
	   }
	  }